﻿# -*-coding:  UTF-8
# @Time    :  2021/9/13 11:14
# @Author  :  Cooper
# @FileName:  登录窗口.py
# @Software:  PyCharm
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPixmap, QIcon
import sys


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(340, 230)
        self.label = QtWidgets.QLabel(Form)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.label.setGeometry(QtCore.QRect(30, 50, 70, 15))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(30, 100, 70, 15))
        self.label_2.setObjectName("label_2")
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(120, 50, 170, 20))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(Form)
        self.lineEdit_2.setGeometry(QtCore.QRect(120, 100, 170, 20))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
        # self.lineEdit_2.setValidator(QtGui.QIntValidator(10000000, 99999999))
        self.lineEdit_2.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp('^\d{8}')))
        self.pushButton = QtWidgets.QPushButton(Form)
        # self.pushButton = QtWidgets.QPushButton('登录(&D)', self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(30, 160, 90, 30))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.setIcon(QIcon(QPixmap('login.ico')))
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(200, 160, 90, 30))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_2.setIcon(QIcon(QPixmap('exit.ico')))
        self.retranslateUi(Form)
        self.pushButton.clicked.connect(self.login)
        # self.pushButton.setShortcut('alt+d')
        self.pushButton.setShortcut('ctrl+d')
        # self.pushButton.setShortcut('shift+p')
        self.pushButton_2.clicked.connect(Form.close)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "系统登录"))
        self.label.setText(_translate("Form", "用户名："))
        self.label_2.setText(_translate("Form", "密  码："))
        self.pushButton.setText(_translate("Form", "登录"))
        self.pushButton.setShortcut('Ctrl+C')
        self.pushButton_2.setText(_translate("Form", "退出"))

    def login(self):
        print('进入登录函数')
        from PyQt5.QtWidgets import QMessageBox
        # 使用information（)方法弹出消息提示框
        QMessageBox.information(MainWindow, '登录消息', '用户名： ' + self.lineEdit.text() + ' 密码： '
                                + self.lineEdit_2.text(), QMessageBox.Ok)

    # 登录按钮单击事件
    def onclick(self):
        if self.lineEdit.text() == "mingri":
            if self.lineEdit_2.text() == '666666':
                MainWindow.close()
                MainWindow.show()  # 显示窗口
            else:
                self.passWordEdit.setText('密码错误请重新输入')
        else:
            self.userEdit.setText('账号错误请重新输入')


# 主方法，程序从此处启动PyQt设计的窗体
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()  # 创建窗体对象
    ui = Ui_Form()  # 创建PyQt设计的窗体对象
    ui.setupUi(MainWindow)  # 调用PyQt窗体的方法对窗体对象进行初始化设置
    MainWindow.show()  # 显示窗体
    sys.exit(app.exec_())  # 程序关闭时退出进程
